_DataGrid_ROWSORT = Class.create({
  initialize : function(column, sortDirection) {
    this._column = column;
    this._sortDirection = sortDirection;
  },
  getColumn: function() {
    return this._column;
  },
  getSortDirection: function() {
    return this._sortDirection;
  },
  compare: function (sortEvent, rowIndex1, rowIndex2) {
    return 0;
  }
});

DataGrid_ROWSTRINGSORT = Class.create(_DataGrid_ROWSORT, {
  compare: function (sortEvent, rowIndex1, rowIndex2) {
    var dataGrid = sortEvent.dataGridComponent;
    var s1 = new String(dataGrid.getCellValue(rowIndex1, this.getColumn())).toLowerCase();
    var s2 = new String(dataGrid.getCellValue(rowIndex2, this.getColumn())).toLowerCase();

    var result = s1 == s2 ? 0 : s1 < s2 ? -1 : 1; 
    
    if (this.getSortDirection() == "desc")
      return result * -1;
    return result;
  }
});

DataGrid_ROWNUMBERSORT = Class.create(_DataGrid_ROWSORT, {
  compare: function (sortEvent, rowIndex1, rowIndex2) {
    var dataGrid = sortEvent.dataGridComponent;
    var n1 = 0 + dataGrid.getCellValue(rowIndex1, this.getColumn());
    var n2 = 0 + dataGrid.getCellValue(rowIndex2, this.getColumn());

    var result = n1 == n2 ? 0 : n1 < n2 ? -1 : 1; 
    
    if (this.getSortDirection() == "desc")
      return result * -1;
    return result;
  }
});

DataGrid_ROWSELECTSORT = Class.create(_DataGrid_ROWSORT, {
  compare: function (sortEvent, rowIndex1, rowIndex2) {
    var dataGrid = sortEvent.dataGridComponent;
    var controller = DataGridControllers.getController("select");

    var s1 = new String(controller.getDisplayValue(dataGrid.getCellEditor(rowIndex1, this.getColumn()))).toLowerCase();
    var s2 = new String(controller.getDisplayValue(dataGrid.getCellEditor(rowIndex2, this.getColumn()))).toLowerCase();

    var result = s1 == s2 ? 0 : s1 < s2 ? -1 : 1; 
    
    if (this.getSortDirection() == "desc")
      return result * -1;
    return result;
  }
});